package com.iafme.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import com.iafme.dto.req.WorkReqDTO;
import com.iafme.dto.res.WorkResDTO;
import com.iafme.model.Work;
import com.iafme.mapper.WorkMapper;
import com.iafme.service.IWorkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author summer
 * @since 2025/01/05 21:14:44
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WorkServiceImpl extends ServiceImpl<WorkMapper, Work> implements IWorkService {

    @Override
    public WorkResDTO saveOrUpdateWork(WorkReqDTO workReqDTO) {
        Work convert = Convert.convert(Work.class, workReqDTO);
        convert.setMemberId(StpUtil.getLoginIdAsInt());
        this.saveOrUpdate(convert);
        return Convert.convert(WorkResDTO.class, convert);
    }
}
